package com.ruoyi.member.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.member.domain.Comment;
import com.ruoyi.member.service.ICommentService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 评论管理Controller
 *
 * @author ruoyi
 */
@RestController
@RequestMapping("/member/comment")
public class CommentController extends BaseController
{
    @Autowired
    private ICommentService commentService;

    /**
     * 查询评论列表
     */
    @PreAuthorize("@ss.hasPermi('member:comment:list')")
    @GetMapping("/list")
    public TableDataInfo list(Comment comment)
    {
        startPage();
        List<Comment> list = commentService.selectCommentList(comment);
        return getDataTable(list);
    }

    /**
     * 获取评论详细信息
     */
    @PreAuthorize("@ss.hasPermi('member:comment:query')")
    @GetMapping(value = "/{commentId}")
    public AjaxResult getInfo(@PathVariable("commentId") Long commentId)
    {
        return AjaxResult.success(commentService.selectCommentById(commentId));
    }

    /**
     * 审核评论
     */
    @PreAuthorize("@ss.hasPermi('member:comment:audit')")
    @Log(title = "评论审核", businessType = BusinessType.UPDATE)
    @PutMapping("/audit")
    public AjaxResult audit(@RequestBody Comment comment)
    {
        return toAjax(commentService.auditComment(comment));
    }

    /**
     * 批量审核通过
     */
    @PreAuthorize("@ss.hasPermi('member:comment:audit')")
    @Log(title = "批量审核通过", businessType = BusinessType.UPDATE)
    @PutMapping("/approve/{commentIds}")
    public AjaxResult approve(@PathVariable Long[] commentIds)
    {
        return toAjax(commentService.approveComments(commentIds));
    }

    /**
     * 批量审核拒绝
     */
    @PreAuthorize("@ss.hasPermi('member:comment:audit')")
    @Log(title = "批量审核拒绝", businessType = BusinessType.UPDATE)
    @PutMapping("/reject/{commentIds}")
    public AjaxResult reject(@PathVariable Long[] commentIds)
    {
        return toAjax(commentService.rejectComments(commentIds));
    }

    /**
     * 删除评论
     */
    @PreAuthorize("@ss.hasPermi('member:comment:remove')")
    @Log(title = "评论管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commentIds}")
    public AjaxResult remove(@PathVariable Long[] commentIds)
    {
        return toAjax(commentService.deleteCommentByIds(commentIds));
    }

    /**
     * 回复评论
     */
    @PreAuthorize("@ss.hasPermi('member:comment:reply')")
    @Log(title = "回复评论", businessType = BusinessType.INSERT)
    @PostMapping("/reply")
    public AjaxResult reply(@RequestBody Comment comment)
    {
        return toAjax(commentService.replyComment(comment));
    }
}